package com.example.imtoken.modules.private_import.fragment.plaintext

import com.blankj.utilcode.util.ClipboardUtils
import com.blankj.utilcode.util.ToastUtils
import com.example.imtoken.R
import com.example.imtoken.core.base.BaseFragment
import com.example.imtoken.databinding.PlaintextFragmentBinding

class PlaintextFragment :
    BaseFragment<PlaintextViewModel, PlaintextFragmentBinding>(PlaintextViewModel::class.java) {


    override fun initLayoutId(): Int {
        return R.layout.plaintext_fragment
    }

    override fun init() {
        initClick()
        initObserve()
    }

    private fun initClick() {
        dataBinding.tvCopy.setOnClickListener {
            ClipboardUtils.copyText(viewModel.value.value)
            ToastUtils.showShort(R.string.copySuccess)
        }
    }

    private fun initObserve() {
        viewModel.value.observe(this) {
            dataBinding.tvValue.text = it
        }
    }

    fun setPrivateData(importType: Int?, value: String?) {
        dataBinding.tvCopy.text = when (importType) {
            1 -> {
                getString(R.string.copyKeyStore)
            }
            2 -> {
                getString(R.string.copyPrivateKey)
            }
            else -> null
        }
        viewModel.setValue(value)
    }

}